package com.wjc.system.controller.admin;


import com.wjc.server.dto.CommonDto;
import com.wjc.server.dto.PageDto;
import com.wjc.server.dto.ResourceDto;
import com.wjc.server.service.ResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/admin/resource")
public class ResourceController {

    private static final Logger LOG= LoggerFactory.getLogger(ResourceController.class);
    public static final String BUSINESS_NAME = "资源";

    @Resource
    private ResourceService resourceService;

    //查询
    @GetMapping("/list")
    public CommonDto list(@Valid  PageDto pageDto){
         resourceService.list(pageDto);
//         LOG.info("分页有啥: {}",pageDto);
        CommonDto<PageDto> pageDtoCommonDto = new CommonDto<>();
        pageDtoCommonDto.setContent(pageDto);
        return pageDtoCommonDto;
    }

    //保存
    @PostMapping("/save")
    public CommonDto save(@RequestBody String jsonStr) {
        CommonDto responseDto = new CommonDto();
        resourceService.saveJson(jsonStr);
        return responseDto;
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonDto delete(@PathVariable String id){
        CommonDto commonDto=new CommonDto<>();
        resourceService.delete(id);
        return commonDto;
    }
    /**
     * 资源树查询
     */
    @GetMapping("/load-tree")
    public CommonDto loadTree() {
        CommonDto responseDto = new CommonDto<>();
        List<ResourceDto> resourceDtoList = resourceService.loadTree();
        responseDto.setContent(resourceDtoList);
        return responseDto;
    }
}
